package org.ssm.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.ssm.pojo.User;

import java.util.List;

public interface UserDao {
@Select(" SELECT * FROM user ")
    public List<User> selelctAll();
@Select("SELECT * FROM user where uid=#{uid}")
    public User selectOne(Integer uid);
    @Update("insert into user(uid,name,age,sex,address,sal) values(#{arg0},#{arg1},#{arg2},#{arg3},#{arg4},#{arg5})")
    public void  insertUser(int uid,String name,int age,String sex,String address,double sal);
    @Update("delete from user where uid=#{uid}")
    public void deleteUser(Integer uid);
    @Update("update user set name=#{arg1}, age=#{arg2}, sex=#{arg3},address=#{arg4}, sal =#{arg5} where uid =#{arg0}")
    public void updateUSer(int uid,String name,int age,String sex,String address,double sal);
    @Select(value = {
            "<script>",
            "select * from user " ,
           "<where>" ,
            "     <if test=\"uid!=null and uid!=''\">" ,
            "          and uid =#{uid} " ,
            "     </if>" ,
            "     <if test=\"name!=null and name!=''\">" ,
            "          and name like CONCAT('%', #{name}, '%') " ,
            "     </if>" ,
            "     <if test=\" address!=null and address!='' \">" ,
            "          and address=#{address} " ,
            "     </if>" ,
            "</where>",
            "</script>"
    })
    public List<User> selectByCondition(@Param("uid") Integer uid,@Param("name") String name, @Param("address") String address);
}
